package com.cinema;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import query.DataQuery;

import com.cinema.data.FilmInfo;

public class FilmDetail extends HttpServlet{

	/**
	 * 
	 */
	public FilmDetail(){
		super();
	}
	private static final long serialVersionUID = 4010782057746594985L;
	public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
		doPost(req, resp);
	}
	
	public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException {
		Long fid = Long.parseLong(request.getParameter("id"));
		
		DataQuery query = new DataQuery();
		FilmInfo film = query.getFilm(fid);
		if(film != null){
			request.setAttribute("film", film);
			String url = "/FilmDetail.jsp";
			RequestDispatcher dispatcher = this.getServletContext().getRequestDispatcher(url);
			try {
				dispatcher.forward(request, response);
			} catch (ServletException e) {
				e.printStackTrace();
			}
		}else
			response.sendRedirect("index.jsp");
	}
}